package com.shenzhen.group.niuniu.operation;

import com.shenzhen.group.common.card.operation.CardCalculate;
import com.shenzhen.group.common.entity.HandCardGroupBase;
import com.shenzhen.group.common.enumeration.CardCompareEnum;
import com.shenzhen.group.common.result.CardResult;

/**
 * @author qiufei
 * @date 2021/9/20 13:19
 * @description 牛牛计算类
 */
public class NiuniuCardCalculate {
    public static int cardCalculate(int[] num) {
        int[] dp = new int[10];
        for (int i = 0; i < num.length - 1; i++) {
            for (int j = i + 1; j < num.length; j++) {
                int index = 4 * i - (i * (i - 1)) / 2 + j - i - 1;
                dp[index] = num[i] + num[j];
            }
        }
        int sum = -1;
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < num.length; j++) {
                int[] res = reflectInt(i);
                if (res[0] == j || res[1] == j) {
                    continue;
                }
                if ((num[j] + dp[i]) % 10 == 0) {
                    for (int k = 0; k < num.length; k++) {
                        if (res[0] != k && res[1] != k && j != k) {
                            sum += num[k];
                        }
                    }
                    int value = (sum + 1) % 10;
                    return value == 0 ? 10 : value;
                }
            }
        }
        return sum;
    }

    public static int[] reflectInt(int index) {
        int[] res = new int[2];
        switch (index) {
            case 0:
                res[0] = 0;
                res[1] = 1;
                break;
            case 1:
                res[0] = 0;
                res[1] = 2;
                break;
            case 2:
                res[0] = 0;
                res[1] = 3;
                break;
            case 3:
                res[0] = 0;
                res[1] = 4;
                break;
            case 4:
                res[0] = 1;
                res[1] = 2;
                break;
            case 5:
                res[0] = 1;
                res[1] = 3;
                break;
            case 6:
                res[0] = 1;
                res[1] = 4;
                break;
            case 7:
                res[0] = 2;
                res[1] = 3;
                break;
            case 8:
                res[0] = 2;
                res[1] = 4;
                break;
            case 9:
                res[0] = 3;
                res[1] = 4;
                break;
            default:
                throw new IllegalArgumentException("输入的参数不合法！");
        }
        return res;
    }

}
